package com.j2eefast.flowable.bpm.service;


import cn.hutool.core.util.IdUtil;
import com.j2eefast.flowable.bpm.entity.bpmCrmMaintenanceEntity;
import com.j2eefast.flowable.bpm.mapper.bpmCrmMaintenanceMapper;
import com.j2eefast.common.core.mutidatasource.annotaion.DataSource;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.common.core.utils.ToolUtil;
import com.j2eefast.framework.utils.Constant;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.Arrays;
/**
 *
 * 维修Service接口
 * @author: yhli
 * @date 2020-06-28 21:58
 */
@Service
public class bpmCrmMaintenanceService extends ServiceImpl<bpmCrmMaintenanceMapper,bpmCrmMaintenanceEntity> {

	@Resource
	private bpmCrmMaintenanceMapper bpmCrmMaintenanceMapper;

	/**
	 * mybaitis-plus 页面分页查询
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params) {
        QueryWrapper<bpmCrmMaintenanceEntity> queryWrapper = new QueryWrapper<bpmCrmMaintenanceEntity>();
              String saleCode = (String) params.get("saleCode");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleCode), "sale_code", saleCode);
                               String saleUserid = (String) params.get("saleUserid");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleUserid), "sale_userid", saleUserid);
          String saleOrderNumber = (String) params.get("saleOrderNumber");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleOrderNumber), "sale_order_number", saleOrderNumber);
          String outCarVin = (String) params.get("outCarVin");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVin), "out_car_vin", outCarVin);
          String outCarVehicle = (String) params.get("outCarVehicle");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVehicle), "out_car_vehicle", outCarVehicle);
          String orderCarContacts = (String) params.get("orderCarContacts");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderCarContacts), "order_car_contacts", orderCarContacts);
          String orderCarPlanInTime = (String) params.get("orderCarPlanInTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderCarPlanInTime), "order_car_plan_in_time", orderCarPlanInTime);
          String orderCarLastDeliveryTime = (String) params.get("orderCarLastDeliveryTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderCarLastDeliveryTime), "order_car_last_delivery_time", orderCarLastDeliveryTime);
          String orderCarPosition = (String) params.get("orderCarPosition");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderCarPosition), "order_car_position", orderCarPosition);
             String orderCarLossFilepath = (String) params.get("orderCarLossFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderCarLossFilepath), "order_car_loss_filepath", orderCarLossFilepath);
          String commissionerPlanGiveTime = (String) params.get("commissionerPlanGiveTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionerPlanGiveTime), "commissioner_plan_give_time", commissionerPlanGiveTime);
          String commissionerRepairMethod = (String) params.get("commissionerRepairMethod");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionerRepairMethod), "commissioner_repair_method", commissionerRepairMethod);
          String commissionerOffer = (String) params.get("commissionerOffer");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionerOffer), "commissioner_offer", commissionerOffer);
          String commissionerOfferFilepath = (String) params.get("commissionerOfferFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionerOfferFilepath), "commissioner_offer_filepath", commissionerOfferFilepath);
          String maintenanceCheckFilepath = (String) params.get("maintenanceCheckFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(maintenanceCheckFilepath), "maintenance_check_filepath", maintenanceCheckFilepath);
          String maintenanceStatus = (String) params.get("maintenanceStatus");
         queryWrapper.eq(ToolUtil.isNotEmpty(maintenanceStatus), "maintenance_status", maintenanceStatus);
          String maintenanceSettlementFilepath = (String) params.get("maintenanceSettlementFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(maintenanceSettlementFilepath), "maintenance_settlement_filepath", maintenanceSettlementFilepath);
          String maintenanceTotalPrice = (String) params.get("maintenanceTotalPrice");
         queryWrapper.eq(ToolUtil.isNotEmpty(maintenanceTotalPrice), "maintenance_total_price", maintenanceTotalPrice);
     		Page<bpmCrmMaintenanceEntity> page = bpmCrmMaintenanceMapper.selectPage(new Query<bpmCrmMaintenanceEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }

    /**
     * 自定义分页查询，含关联实体对像
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params,bpmCrmMaintenanceEntity bpmCrmMaintenanceEntity) {
		Page<bpmCrmMaintenanceEntity> page = bpmCrmMaintenanceMapper.findPage(new Query<bpmCrmMaintenanceEntity>(params).getPage(), bpmCrmMaintenanceEntity,(String) params.get(Constant.SQL_FILTER))  ;
		return new PageUtil(page);
	}
	/**
     * 批量删除
     */
    @DataSource(name="FLOWABLE")
	@Transactional(rollbackFor = Exception.class)
	public boolean deletebpmCrmMaintenanceByIds(String[] ids) {
		return removeByIds(Arrays.asList(ids));
	}

	/**
     * 单个删除
     */
    @DataSource(name="FLOWABLE")
	public boolean deletebpmCrmMaintenanceById(String id) {
		return removeById(id);
	}

	/**
     * 保存
     */
    @DataSource(name="FLOWABLE")
	public boolean savebpmCrmMaintenance(bpmCrmMaintenanceEntity bpmCrmMaintenance){
        bpmCrmMaintenance.setId(IdUtil.fastSimpleUUID());
        return save(bpmCrmMaintenance);
    }

	/**
     * 修改根居ID
     */
    @DataSource(name="FLOWABLE")
	public boolean updatebpmCrmMaintenanceById(bpmCrmMaintenanceEntity bpmCrmMaintenance) {
		return updateById(bpmCrmMaintenance);
	}

	/**
     * 根居ID获取对象
     */
    @DataSource(name="FLOWABLE")
	public bpmCrmMaintenanceEntity getbpmCrmMaintenanceById(String id){
		return getById(id);
	}
}
